import { Toast } from 'mint-ui';  //引入弹框
import { MessageBox } from 'mint-ui';

export default {
	/* start 金额数据处理 */
	formatMoney  (num, n) {
	    if(isNaN(num*1)){
	      return num;
      }{
        if(undefined ==  num || "" == num || null == num || "0" == num){
          return "0.00";
        }else{
          num = String(Number(num).toFixed(n ? n : 2));
          var re = /(-?\d+)(\d{3})/;
          while (re.test(num)) num = num.replace(re, "$1,$2");
          return n ? num : num.replace(/^([0-9,]+\.[1-9])0$/, "$1").replace(/^([0-9,]+)\.00$/, "$1");
        }
      }
	},
	/* end 金额数据处理 */
	/*start rules*/
	rules:{
		num:/^\d*$/,  //校验是否为num
		phone:/^(13[0-9]|14[57]|15[012356789]|18[012356789]|17[67])\d{8}$/,  //校验电话
		pass:/^([0-9])\d{5}$/,  //校验支付密码  6位纯数字
		//6-20 位，字母、数字、字符
		password:/^(\w){6,20}$/,		//登陆密码
	},
	/*end rules*/
	/* start 弹框 */
	vFun_openSuccess(msg){
		Toast({
		  message: msg,
		  iconClass: 'fontSize iconfont icon-chenggong'
		});
	},
	vFun_openError(msg){
		Toast({
		  message: msg,
		  iconClass: 'fontSize iconfont icon-shibai'
		});
	},
	vFun_openInfo(msg){
		Toast({
		  message: msg
		});
	},
	/* end 弹框 */

	/* start 右上角成功提示 */
	openSuccess(_this,msg) {
		_this.$notify({
			message: msg,
			type: 'success',
			duration: 3000
		});
	},
	/* end 右上角成功提示 */
	/* start 右上角失败提示 */
	openError(_this,msg) {
		_this.$notify({
			message: msg,
			type: 'error',
			duration: 3000
		});
	},
	/* end 右上角失败提示 */
	/* start 右上角失败提示 */
	openInfo(_this,msg) {
		_this.$notify({
			message: msg,
			type: 'info',
			duration: 3000
		});
	},
	/* end 右上角失败提示 */
	/* start cookie */
	setCookie(c_name, value, expiredays){
		var exdate=new Date();
		exdate.setDate(exdate.getDate() + expiredays);
		document.cookie=c_name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	},
	getCookie(name){
		var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
		if(arr=document.cookie.match(reg)){
			return unescape(arr[2]);
		}else{
			return null;
		}
	},
	delCookie(name){
		var exp = new Date();
		exp.setTime(exp.getTime() - 1);
		var cval= this.getCookie(name);
		if(cval!=null)
		document.cookie= name + "="+cval+";expires="+exp.toGMTString();
	},
	/* end cookie */
	/* start 数组去重 */
	array_remove_repeat(a) {
	    var r = [];
	    for(var i = 0; i < a.length; i ++) {
	        var flag = true;
	        var temp = a[i];
	        for(var j = 0; j < r.length; j ++) {
	            if(temp === r[j]) {
	                flag = false;
	                break;
	            }
	        }
	        if(flag) {
	            r.push(temp);
	        }
	    }
	    return r;
	},
	/* end 数组去重 */
	/* start 数组组合 */
    arraysplitAll(a){
        var result =[];

        if(a.length==0){
            return result;
        }else if(a.length==1){
            return a[0];
        }else if(a.length==2){
            return arraysplit(a[0],a[1]);
        }else{
            result = arraysplit(a[0],a[1]);
            a.splice(0,2);
            for(var i=0;i< a.length;i++){
                var temp = arraysplit(result,a[i]);
                result = temp;
            }
            return result;
        };

        function arraysplit(array1,array2){
            var result = [];
            if(array1.length==0&&array2.length==0){
            	result.push(",")
                return result;
            }else if(array1.length==0&&array2.length!=0){
                for(var j=0;j<array2.length;j++){
                    result.push(','+array2[j]);
                }
                return result;
            }else if(array1.length!=0&&array2.length==0){
                for(var i=0;i<array1.length;i++){
                    result.push(array1[i]+',');
                }
                return result;
            }else{
                for(var i=0;i<array1.length;i++){
                    for(var j=0;j<array2.length;j++){
                        result.push(array1[i]+','+array2[j]);
                    }
                }
           		return result;
            }
        }
    },
	/* end 数组组合 */


}
